package review;

import java.util.Arrays;

public class test1 {
    public static void main(String[] args) {
        int[] arr=new int[]{1,2,7,4,14,10,15};
        tranform(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void tranform(int[] arr){
        //偶数在前，奇数在后
        int i=0;
        int j= arr.length-1;
        while (i<j){
            while (i<j && arr[i]%2==0){
                i++;
            }
            while (i<j&& arr[j]%2!=0){
                j--;
            }
            int temp=arr[i];
            arr[i]=arr[j];
            arr[j]=temp;
            i++;
            j--;
        }

    }


    public static int[] bubbleSort(int[] arr){
        //冒泡排序
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1; j++) {
                if (arr[i]>arr[i+1]){
                    int temp=arr[i];
                    arr[i]=arr[i+1];
                    arr[i+1]=temp;
                }
            }
        }return arr;
    }


    public static boolean orderly(int[] arr){
        //有序数组
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i]>arr[i+1]){
                return false;
            }
        }return true;
    }


    public static int erfenSearch(int[] arr,int find){
        //二分查找
        int left=0;
        int right= arr.length-1;
        while (left<=right){
            int mid=(left+right)/2;
            if (find<arr[mid]){
                right=mid-1;
            } else if(find>arr[mid]) {
                left=mid+1;
            }else{
                return arr[mid];
            }
        }
        return -1;
    }

    public static int Find(int[] arr,int find){
        //查找元素
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==find){
                return i;
            }
        }
        return -1;
    }

    public static double average(int[] arr){
        //平均值
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        //转换为double,小数
        return sum/ (double)arr.length;
    }


   public static int max(int[] arr){
        //最大值
        int max=arr[0];
       for (int i = 1; i < arr.length; i++) {
           if (arr[i]>max){
               max=arr[i];
           }
       }
       return max;
   }


}
